<!-- 
 * 基于BaseFlvPlayer的简单播放器
 * 
 * @Author: bobo
 * @Date: 2021-01-27 
 -->
<template>
  <div>
    <div class="custom-toolbar-container">
      <p>这是标题栏2</p>
    </div>
    <!--媒体控制区域背景 -->
    <transition name="fade">
      <div class="custom-video_control" v-show="isShowControls">
        <div class="custom-video_play_container">
          <span v-if="isPlaying" class="custom-video_play-pause iconfont icon-zanting" @click="f_pause"></span>
          <span v-else class="custom-video_play-play iconfont icon-bofang" @click="f_play"></span>
        </div>

        <!-- 进度条 -->
        <div class="custom-video_control-bg">
          <div class="custom-video_control-bg-outside" ref="custom-video_control-bg-outside">
            <span class="custom-video_control-bg-inside-progress" ref="custom-video_control-bg-inside-progress"></span>
            <span class="custom-video_control-bg-inside-play" ref="custom-video_control-bg-inside-play"></span>
            <span
              v-show="showProgressbarPointer"
              class="custom-video_control-bg-inside-point"
              ref="custom-video_control-bg-inside-point"
            ></span>
          </div>
        </div>
        <!-- 时间 -->
        <div class="custom-video_control-time">
          <span>{{ showPlayTime }}</span>
          /
          <span>{{ showDuration }}</span>
        </div>
        <!-- 声音 -->
        <div class="custom-video_control-voice">
          <span class="custom-video_control-voice-play iconfont icon-yinliang"></span>
          <div class="custom-video_control-voice-bg" ref="custom-video_control-voice-bg">
            <div class="custom-video_control-voice-bg-outside" ref="custom-video_control-voice-bg-outside">
              <span class="custom-video_control-voice-bg-inside" ref="custom-video_control-voice-bg-inside"></span>
              <span class="custom-video_control-voice-bg-point" ref="custom-video_control-voice-bg-point"></span>
            </div>
          </div>
        </div>

        <!-- 全屏缩放 -->
        <div>
          <span
            v-if="!isFullScreen"
            class="custom-video_control-full iconfont icon-quanping"
            @click="f_fullScreen"
          ></span>
          <span v-else class="custom-video_control-full iconfont icon-banping" @click="f_exitFullScreen"></span>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import "@/assets/fonts/player-controls/iconfont.css";
import BasePlayerControls from "@/components/player/BasePlayerControls";
export default {
  extends: BasePlayerControls,
  data() {
    return {
      //布局元素
      progressOutsideEl: null,
      cacheProgressEl: null,
      playProgressEl: null,
      playPointEl: null,
    };
  },
  mounted() {
    this.progressOutsideEl = this.$refs["custom-video_control-bg-outside"];
    this.cacheProgressEl = this.$refs["custom-video_control-bg-inside-progress"];
    this.playProgressEl = this.$refs["custom-video_control-bg-inside-play"];
    this.playPointEl = this.$refs["custom-video_control-bg-inside-point"];

    this.$watch("progressBar.showPlayProgress", (newVal) => {
      this.f_updateProgressbarUi(newVal, this.playPointEl, this.playProgressEl, this.progressOutsideEl.offsetWidth);
    });
    const cacheProgressUnWatch = this.player.$watch("videoOptions.cacheProgress", (newVal) => {
      this.cacheProgressEl.style.width = newVal + "%";
      if (newVal === 100) {
        cacheProgressUnWatch();
      }
    });
    this.player.$on("player-error", (errType, errDetail, info) => {
      console.log("监听播放异常:", errType, errDetail, info);
      this.f_reloadPlay();
    });
    this.f_initProgressbarControl(this.playPointEl, this.playProgressEl, this.progressOutsideEl);
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.custom-toolbar-container {
  width: 100%;
  height: 48px;
  position: absolute;
  background-color: salmon;
  pointer-events: auto;
  display: none;
}

$ctlHeight: 48px;
/* 控制栏 */
.custom-video_control {
  position: absolute;
  width: 100%;
  height: $ctlHeight;
  left: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: row;
  align-items: center;
  pointer-events: auto;
}
/* --------------------暂停 或者 播放的容器-------------------- */
.custom-video_play_container {
  display: flex;
  position: relative;
  left: 0;
  border-radius: 50%;
  color: white;
  align-items: center;
  margin-left: 0.5rem;
}
/* hover 播放按钮容器动画 */
.custom-video_play_container:hover {
  box-shadow: 0 0 3px #9e9da0;
  transition: all 0.4s;
}
/* 暂停隐藏 */
.custom-video_play-pause {
  display: inline-block;
  font-size: 20px;
}
/* 播放*/
.custom-video_play-play {
  display: inline-block;
  font-size: 20px;
}
/* --------------------控制栏进度条-------------------- */
.custom-video_control-bg {
  flex: 1;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 10px;
  margin-right: 10px;
}
/* 控制栏进度条 —— 总长度 */
.custom-video_control-bg-outside {
  width: 100%;
  height: 5px;
  border-radius: 2.5px;
  background-color: rgb(143, 140, 140);
  position: relative;
  cursor: pointer;
}
/* 控制栏进度条 —— 播放长度 */
.custom-video_control-bg-inside-play {
  position: absolute;
  display: inline-block;
  width: 0;
  height: 100%;
  border-radius: 2.5px;
  left: 0;
  top: 0;
  background-color: #fff;
  transition: all 0.2s;
}

/* 控制栏进度条 —— 缓冲长度 */
.custom-video_control-bg-inside-progress {
  position: absolute;
  display: inline-block;
  width: 0;
  height: 100%;
  border-radius: 2.5px;
  left: 0;
  top: 0;
  background-color: rgb(167, 164, 164);
  transition: all 0.2s;
}

/* 控制栏进度条 —— 播放点 */
.custom-video_control-bg-inside-point {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  top: -3px;
  left: -3px;
  transition: all 0.2s;
}

/*--------------------控制栏 —— 声音-------------------------*/
.custom-video_control-voice {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  color: #fff;
  position: relative;
}
.custom-video_control-voice:hover > .custom-video_control-voice-bg {
  display: block;
}
.custom-video_control-voice-play {
  z-index: 10;
  font-size: 16px;
}
.custom-video_control-voice-bg {
  display: none;
  position: absolute;
  width: 30px;
  height: 100px;
  background-color: rgba(0, 0, 0, 0.55);
  left: 0;
  bottom: 0px;
  border-radius: 15px;
}
.custom-video_control-voice-bg-outside {
  width: 5px;
  height: 70px;
  border-radius: 2.5px;
  background-color: #aaa;
  position: absolute;
  left: 50%;
  transform: translate3d(-50%, 10%, 0);
  cursor: pointer;
}
.custom-video_control-voice-bg-inside {
  display: inline-block;
  position: absolute;
  width: 100%;
  bottom: 0;
  left: 0;
  border-radius: 2.5px;
  background-color: #fff;
  height: 0;
}
.custom-video_control-voice-bg-point {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  left: -3px;
  bottom: -1px;
}

.custom-video_control-voice {
  width: 30px;
  height: 30px;
  cursor: pointer;
}
/*-------------------- 控制栏-时间 --------------------*/

.custom-video_control-time {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  color: #fff;
  position: relative;
  font-size: 12px;
  padding-left: 4px;
  padding-right: 4px;
}
/*-------------------- 控制栏-全屏图标 --------------------*/
.custom-video_control-full {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  color: #fff;
  position: relative;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 20px;
}
/*-------------------- 控制栏隐藏动画 --------------------*/
.fade-enter-active {
  transition: all 0.3s ease;
}
.fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>